package DAO;

import entity.Emp;
import utils.DBUtils;

import java.util.List;

/**
 * @author lvtian
 * @date 2022/12/20 15:02
 */
public class EmpDAOImpl implements EmpDAO {
    //查询所有员工
    @Override
    public List<Emp> selectEmp() {
        List<Emp> emps = DBUtils.executeQuery(Emp.class, "select * from emp");
        return emps;
    }
//添加员工
    @Override
    public int insertEmp(Emp emp) {
        int i = DBUtils.executeUpdate("insert into emp(id,e_name,e_age,e_gender) values(?,?,?,?)",
                emp.getId(), emp.getName(), emp.getAge(), emp.getGender());
        return i;
    }
//修改信息
    @Override
    public int updateEmp(Emp emp) {
        int i = DBUtils.executeUpdate("update emp set e_name=? ,e_age=?,e_gender=? where id=?",
                emp.getName(), emp.getAge(), emp.getGender(), emp.getId());
        return i;
    }
//删除员工
    @Override
    public int deleteEmp(int id) {
        int i = DBUtils.executeUpdate("delete from emp where id=?", id);
        return i;
    }
//通过id查询员工
    @Override
    public List<Emp> selectEmpById(int id) {
        List<Emp> emps = DBUtils.executeQuery(Emp.class, "select * from emp where id =?",id);
        return emps;
    }
//查找重名
    @Override
    public List<Emp> selectEmpByName(String name) {
        List<Emp> emps = DBUtils.executeQuery(Emp.class, "select * from emp where e_name =?",name);
        return emps;
    }
}
